﻿namespace WMS6.Web.Billing
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BillingServiceRef;
    using WMS6.Web.UserControls;

    public class BillingDailyInvDetail : BasePage
    {
        protected Button btnExport;
        protected Button btnGoBack;
        protected HtmlForm F9232;
        protected GridView gvBillingDailyInvDetail;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnOwnerID;
        protected HtmlInputHidden hdnRtnValue;
        protected Label lblBillingOrderList;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        protected UpdatePanel up1;

        private void BindData2BillingDailyInvDetailList(BillingCredenceQueryEntity billingCredenceQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(billingCredenceQueryEntity.CurrentPage);
            DataSet ds = new DataSet();
            ds = BillingServiceClientProxy.GetInstance().GetBillingCredenceByQueryList(billingCredenceQueryEntity);
            base.BindData2GridView(this.gvBillingDailyInvDetail, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            BillingCredenceQueryEntity billingCredenceQueryEntity = this.GetBillingCredenceQueryEntity();
            billingCredenceQueryEntity.IsGetAll = true;
            string currentPageIndex = billingCredenceQueryEntity.CurrentPage;
            billingCredenceQueryEntity.CurrentPage = "0";
            this.gvBillingDailyInvDetail.Columns[1].Visible = false;
            this.gvBillingDailyInvDetail.AllowSorting = false;
            this.BindData2BillingDailyInvDetailList(billingCredenceQueryEntity);
            this.hdnActionID.Value = "";
            this.gvBillingDailyInvDetail.ShowFooter = false;
            billingCredenceQueryEntity.IsGetAll = false;
            billingCredenceQueryEntity.CurrentPage = currentPageIndex;
            this.SetBillingCredenceQueryEntity(billingCredenceQueryEntity);
            this.hdnActionID.Value = "";
            base.Export2Excel("BillingDailyInvDetail.xls", this.gvBillingDailyInvDetail);
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            BillingCredenceQueryEntity billingCredenceQueryEntity = this.GetBillingCredenceQueryEntity();
            billingCredenceQueryEntity.CurrentPage = "0";
            this.BindData2BillingDailyInvDetailList(billingCredenceQueryEntity);
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("BillingDailyInvList.aspx?from=edit", false);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            BillingCredenceQueryEntity billingCredenceQueryEntity = this.GetBillingCredenceQueryEntity();
            billingCredenceQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2BillingDailyInvDetailList(billingCredenceQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            BillingCredenceQueryEntity billingCredenceQueryEntity = this.GetBillingCredenceQueryEntity();
            if (int.Parse(billingCredenceQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                billingCredenceQueryEntity.CurrentPage = (int.Parse(billingCredenceQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2BillingDailyInvDetailList(billingCredenceQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            BillingCredenceQueryEntity billingCredenceQueryEntity = this.GetBillingCredenceQueryEntity();
            if (int.Parse(billingCredenceQueryEntity.CurrentPage) > 0)
            {
                billingCredenceQueryEntity.CurrentPage = (int.Parse(billingCredenceQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2BillingDailyInvDetailList(billingCredenceQueryEntity);
            }
        }

        private BillingCredenceQueryEntity GetBillingCredenceQueryEntity()
        {
            if (!string.IsNullOrEmpty(this.hdnActionID.Value))
            {
                return (base.PageQueryEntityViewState as BillingCredenceQueryEntity);
            }
            return (base.PageQueryEntitySession as BillingCredenceQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                BillingCredenceQueryEntity billingCredenceQueryEntity = this.GetBillingCredenceQueryEntity();
                billingCredenceQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2BillingDailyInvDetailList(billingCredenceQueryEntity);
            }
        }

        protected void gvBillingDailyInvDetail_Init(object sender, EventArgs e)
        {
        }

        protected void gvBillingDailyInvDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
            }
        }

        protected void gvBillingDailyInvDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                BillingCredenceQueryEntity billingCredenceQueryEntity = this.GetBillingCredenceQueryEntity();
                billingCredenceQueryEntity.SortField = e.SortExpression;
                if (billingCredenceQueryEntity.SortDirection == "ASC")
                {
                    billingCredenceQueryEntity.SortDirection = "DESC";
                }
                else if (billingCredenceQueryEntity.SortDirection == "DESC")
                {
                    billingCredenceQueryEntity.SortDirection = "ASC";
                }
                this.BindData2BillingDailyInvDetailList(billingCredenceQueryEntity);
            }
            catch (Exception)
            {
            }
        }

        private void LoadData()
        {
            BillingCredenceQueryEntity billingCredenceQueryEntity = new BillingCredenceQueryEntity {
                CredenceType = base.GetParamsString("InvCharges", "Same As"),
                DocID = base.GetParamsString(base.Request.QueryString["ID"], "Same As"),
                BillingObjectID = base.GetParamsString(base.Request.QueryString["OwnerID"], "Same As"),
                IsGetAll = false,
                CurrentPage = "0",
                PageSize = this.gvBillingDailyInvDetail.PageSize.ToString(),
                SortField = "DOC_ID",
                SortDirection = "ASC"
            };
            this.PagerFooter.PageSize = this.gvBillingDailyInvDetail.PageSize;
            this.SetBillingCredenceQueryEntity(billingCredenceQueryEntity);
            this.BindData2BillingDailyInvDetailList(billingCredenceQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetBillingCredenceQueryEntity(BillingCredenceQueryEntity billingCredenceQueryEntity)
        {
            if (!string.IsNullOrEmpty(this.hdnActionID.Value))
            {
                base.PageQueryEntityViewState = billingCredenceQueryEntity;
            }
            else
            {
                base.PageQueryEntitySession = billingCredenceQueryEntity;
            }
        }
    }
}

